const date = new Date()
const years = []
const months = []
const days = []
const hours = []
const minutes = []
for (let i = 1990; i <= date.getFullYear(); i++) {
  years.push(i)
}
for (let i = 1; i <= 12; i++) {
  months.push(i)
}
for (let i = 1; i <= 31; i++) {
  days.push(i)
}
for (let i = 0; i <= 23; i++) {
  hours.push(i)
}
for (let i = 0; i <= 59; i++) {
  minutes.push(i)
}
Page({
  data: {
    selectArea: false,
    selectArea2: false,
    selectArea3: false,
    selectItem: false,
    selectItem2: false,
    selectCom: false,
    menuClose: false,
    searchShow: false,
    settingBox: false,
    selectItem1_shrink: false,
    selectItem2_shrink: false,
    selectItem3_shrink: false,
    selectItem4_shrink: false,
    changeSchoolFlag: false,
    changeHobbyFlag: false,
    collectionFlag: false,
    nowPage: 0,
    changePage: false,
    comPageItem1: false,
    comPageItem2: false,
    comPageItem3: false,
    comLogin: false,
    schLogin: false,
    nameBtn:false,
    nameEdit:false,
    comListBtn: false,
    comList: false,
    x: 0,
    y: 0,
    moveY: null,
    years: years,
    year: date.getFullYear(),
    months: months,
    month: 2,
    days: days,
    day: 2,
    value: [9999, 1, 1],
    hour: hours,
    minute: minutes,
    editFlag:false,
    deleteBtn:false,
    editQrCode:false,
    cancelBtn:false,
    confirmBtn:false,
  },
  onLoad: function() {
    
  },
  setting: function() {
    this.setData({
      settingBox: !this.data.settingBox,
    });
  },
  clickPerson: function() {

    this.setData({
      selectArea: !this.data.selectArea,
    });
  },

  clickPerson2: function() {
    this.setData({
      selectArea2: !this.data.selectArea2,
    });
  },

  clickPerson3: function() {
    console.log('close');
    var that = this;
    if (this.data.selectItem2) {
      this.setData({
        selectItem2: !this.data.selectItem2,
      });
      setTimeout(function() {
        that.setData({
          selectArea3: !that.data.selectArea3,
        });
      }, 400)
    } else {
      this.setData({
        selectArea3: !this.data.selectArea3,
      });
    }
  },

  searchShow: function() {
    this.setData({
      searchShow: !this.data.searchShow,
    });
  },

  mySelect1: function(e) {
    this.setData({
      selectItem2: false,
      selectItem1_shrink: !this.data.selectItem1_shrink,
    });
    var that = this;
    setTimeout(function() {
      that.setData({
        selectItem1_shrink: !that.data.selectItem1_shrink,
      });
    }, 250)
  },

  mySelect2: function(e) {
    this.setData({
      selectItem2: !this.data.selectItem2,
      selectItem2_shrink: !this.data.selectItem2_shrink,
    });
    var that = this;
    setTimeout(function() {
      that.setData({
        selectItem2_shrink: !that.data.selectItem2_shrink,
      });
    }, 250)
  },

  mySelect3: function(e) {
    this.setData({
      selectItem2: false,
      selectItem3_shrink: !this.data.selectItem3_shrink,
    });
    var that = this;
    setTimeout(function() {
      that.setData({
        selectItem3_shrink: !that.data.selectItem3_shrink,
      });
    }, 250)
  },

  mySelect4: function(e) {
    this.setData({
      selectItem2: false,
      selectItem4_shrink: !this.data.selectItem4_shrink,
    });
    var that = this;
    setTimeout(function() {
      that.setData({
        selectItem4_shrink: !that.data.selectItem4_shrink,
      });
    }, 250)
  },

  changeSchool: function() {
    var that = this;
    that.setData({
      changeSchoolFlag: !that.data.changeSchoolFlag,
    });
    setTimeout(function() {
      that.setData({
        changeSchoolFlag: !that.data.changeSchoolFlag,
      });
    }, 750)
  },
  changeHobby: function() {
    var that = this;
    that.setData({
      changeHobbyFlag: !that.data.changeHobbyFlag,
    });
    setTimeout(function() {
      that.setData({
        changeHobbyFlag: !that.data.changeHobbyFlag,
      });
    }, 700)
  },
  myCollection: function() {
    var that = this;
    that.setData({
      collectionFlag: !that.data.collectionFlag,
    });
    setTimeout(function() {
      that.setData({
        collectionFlag: !that.data.collectionFlag,
      });
    }, 650)
  },

  changePage: function(e) {
    console.log(e.target.id);
    if (e.target.id == this.data.nowPage) return;
    else if (this.data.nowPage == 0) {
      this.setData({
        nowPage: 1,
        menuClose: true,
      })
    } else if (this.data.nowPage == 1) {
      this.setData({
        nowPage: 0,
      })
    }
    if (!this.data.selectCom) {
      this.setData({
        changePage: !this.data.changePage,
        selectCom: !this.data.selectCom,
        settingBox: false,
        searchShow: false,
      });
    } else {
      this.setData({
        changePage: !this.data.changePage,
        selectCom: !this.data.selectCom,
        settingBox: false,
      });
    }
  },
  menuClose: function() {
    if (!this.data.menuClose) {
      this.setData({
        menuClose: !this.data.menuClose,
        y: -120
      });
    }
  },
  moveStart: function(e) {
    this.setData({
      moveY: e.changedTouches[0].pageY
    });
  },
  judgeClose: function(e) {
    console.log(e.changedTouches[0].pageY);
    if (e.changedTouches[0].pageY < this.data.moveY) {
      this.setData({
        menuClose: !this.data.menuClose,
        y: 240
      });
    } else {
      this.setData({
        menuClose: !this.data.menuClose,
        settingBox: false,
        searchShow: false,
        y: 0
      });
    }
  },
  judgeClose2: function(e) {
    console.log(e);
    if (e.changedTouches[0].pageY >= this.data.moveY) {
      this.setData({
        menuClose: false,
        searchShow: false,
        y: 0
      });
    } else if (e.changedTouches[0].pageY < this.data.moveY) {
      this.setData({
        menuClose: true,
        settingBox: false,
        y: 240
      });
    }
  },
  comPageItemClick1: function() {
    this.setData({
      comPageItem1: !this.data.comPageItem1,
    })
    var that = this;
    setTimeout(function() {
      that.setData({
        comPageItem1: !that.data.comPageItem1,
      })
    }, 300)
  },
  comPageItemClick2: function() {
    this.setData({
      comPageItem2: !this.data.comPageItem2,
    })
    var that = this;
    setTimeout(function() {
      that.setData({
        comPageItem2: !that.data.comPageItem2,
      })
    }, 300)
  },
  comPageItemClick3: function() {
    this.setData({
      comPageItem3: !this.data.comPageItem3,
    })
    var that = this;
    setTimeout(function() {
      that.setData({
        comPageItem3: !that.data.comPageItem3,
      })
    }, 300)
  },
  comLogin: function() {
    var that = this;
    this.setData({
      comLogin: !that.data.comLogin,
      schLogin: false,
    })
  },
  schLogin: function() {
    var that = this;
    this.setData({
      schLogin: !that.data.schLogin,
      comLogin: false,
    })
  },
  comListShow: function() {
    var that = this
    this.setData({
      comList: !that.data.comList,
      comListBtn: !that.data.comListBtn,
    })
    setTimeout(function() {
      that.setData({
        comListBtn: !that.data.comListBtn,
      })
    }, 200)
  }, 
  nameEdit: function () {
    var that = this
    this.setData({
      nameEdit: !that.data.nameEdit,
      nameBtn: !that.data.nameBtn,
    })
    setTimeout(function () {
      that.setData({
        nameBtn: !that.data.nameBtn,
      })
    }, 200)
  },
  checkComPsw:function(){
    var that = this;
    this.setData({
      comLogin: false,
      schLogin: false,
    })
  },
  checkSchPsw:function(){
    var that = this;
    this.setData({
      comLogin: false,
      schLogin: false,
    })
  },
  editAct:function(e){
    var that=this;
    this.setData({
      editFlag: !that.data.editFlag
    })
  },
  editQrCode:function(){
    var that = this;
    that.setData({
      editQrCode: !that.data.editQrCode
    })
    setTimeout(function () {
      that.setData({
        editQrCode: !that.data.editQrCode
      })
    }, 300)
  },
  deleteBtn: function () {
    var that = this;
    that.setData({
      deleteBtn: !that.data.deleteBtn
    })
    setTimeout(function () {
      that.setData({
        deleteBtn: !that.data.deleteBtn
      })
    }, 300)
  },
  cancelBtn: function () {
    var that = this;
    this.setData({
      cancelBtn: !that.data.cancelBtn,
      editFlag: !that.data.editFlag
    })
    setTimeout(function () {
      that.setData({
        cancelBtn: !that.data.cancelBtn,
      })
    }, 300)
  },
  confirmBtn: function () {
    var that = this;
    this.setData({
      confirmBtn: !that.data.confirmBtn,
      editFlag: !that.data.editFlag
    })
    setTimeout(function () {
      that.setData({
        confirmBtn: !that.data.confirmBtn,
      })
    }, 300)
  },
  tocorAdmin: function(){
    wx.navigateTo({
      url: '../corAdmin/corAdmin',
    })
  },
  toschAdmin: function () {
    wx.navigateTo({
      url: '../schAdmin/schAdmin',
    })
  },
})